/*
 * Ruler.java
 *
 * Created on September 7, 2008, 1:25 PM
 */

package com.leadiv.openrule;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import javax.swing.JComponent;

/**
 *
 * @author  leadiv
 */
public class Ruler extends BaseRuler {

    /** Creates new form Ruler */
    public Ruler() {
        super();
        initComponents();

        this.isTransparable = AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
        this.setRulerColor(Utilities.hstoc(
            Preferences.userPrefs().get("ruler-color", Preferences.DEFAULT_COLOR))
        );

        if(!isTransparable) {
            this.remove(this.tickLeaderBar1);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popContextMenu = new javax.swing.JPopupMenu();
        mtmPreferences = new javax.swing.JMenuItem();
        mtmAbout = new javax.swing.JMenuItem();
        mtmHelp = new javax.swing.JMenuItem();
        mtmSeparator = new javax.swing.JSeparator();
        mtmFlip = new javax.swing.JMenuItem();
        mtmSnap = new javax.swing.JMenuItem();
        mtmSeparator2 = new javax.swing.JSeparator();
        mtmMinimize = new javax.swing.JMenuItem();
        mtmQuit = new javax.swing.JMenuItem();
        pnlRulerContainer = new javax.swing.JPanel();
        pnlInfoBar = new javax.swing.JPanel();
        pnlLeftContainer = new javax.swing.JPanel();
        lblDistance = new javax.swing.JLabel();
        pnlTitle = new javax.swing.JPanel();
        lblTitle = new javax.swing.JLabel();
        pnlFormControls = new javax.swing.JPanel();
        pnlButtons = new javax.swing.JPanel();
        btnFlip = new javax.swing.JButton();
        pnlPadding = new javax.swing.JPanel();
        btnMin = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        pnlResize = new javax.swing.JPanel();
        lblHandle = new javax.swing.JLabel();
        pnlTickBar = new javax.swing.JPanel();
        tickbar = new com.leadiv.openrule.TickBar();
        tickLeaderBar1 = new com.leadiv.openrule.TickLeaderBar(5);
        mbHotKeys = new javax.swing.JMenuBar();
        mnuHotKeys = new javax.swing.JMenu();
        mtmHKFlip = new javax.swing.JMenuItem();
        mtmHKSnap = new javax.swing.JMenuItem();
        mtmHKPreferences = new javax.swing.JMenuItem();
        mtmHKAbout = new javax.swing.JMenuItem();
        mtmHKHelp = new javax.swing.JMenuItem();
        mtmHKMinimize = new javax.swing.JMenuItem();
        mtmHKQuit = new javax.swing.JMenuItem();

        mtmPreferences.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, 0));
        mtmPreferences.setText("Preferences...");
        popContextMenu.add(mtmPreferences);
        mtmPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prefsRuler();
            }
        });

        mtmAbout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, 0));
        mtmAbout.setText("About...");
        popContextMenu.add(mtmAbout);
        mtmAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                about();
            }
        });

        mtmHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        mtmHelp.setText("Help");
        popContextMenu.add(mtmHelp);
        mtmHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gotohelp();
            }
        });
        popContextMenu.add(mtmSeparator);

        mtmFlip.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, 0));
        mtmFlip.setText("Flip");
        popContextMenu.add(mtmFlip);
        mtmFlip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flipRuler();
            }
        });

        mtmSnap.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, 0));
        mtmSnap.setText("Snap to Zero");
        popContextMenu.add(mtmSnap);
        mtmSnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                snap();
            }
        });
        popContextMenu.add(mtmSeparator2);

        mtmMinimize.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, 0));
        mtmMinimize.setText("Minimize");
        popContextMenu.add(mtmMinimize);
        mtmMinimize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minimizeRuler();
            }
        });

        mtmQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, 0));
        mtmQuit.setText("Quit");
        popContextMenu.add(mtmQuit);
        mtmQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeRuler();
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Open Rule");
        setAlwaysOnTop(true);
        setBounds(new java.awt.Rectangle(0, 0, 460, 60));
        setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        setMinimumSize(new java.awt.Dimension(255, 60));
        setUndecorated(true);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
                formWindowLostFocus(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));

        pnlRulerContainer.setBackground(new java.awt.Color(252, 233, 79));
        pnlRulerContainer.setComponentPopupMenu(popContextMenu);
        pnlRulerContainer.setPreferredSize(new java.awt.Dimension(360, 70));
        pnlRulerContainer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                pnlRulerContainerMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                pnlRulerContainerMouseReleased(evt);
            }
        });
        pnlRulerContainer.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                pnlRulerContainerMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                pnlRulerContainerMouseMoved(evt);
            }
        });
        pnlRulerContainer.setLayout(new javax.swing.BoxLayout(pnlRulerContainer, javax.swing.BoxLayout.Y_AXIS));

        pnlInfoBar.setOpaque(false);
        pnlInfoBar.setPreferredSize(new java.awt.Dimension(360, 30));
        pnlInfoBar.setLayout(new java.awt.BorderLayout());

        pnlLeftContainer.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 5, 1, 1));
        pnlLeftContainer.setMinimumSize(new java.awt.Dimension(50, 14));
        pnlLeftContainer.setOpaque(false);
        pnlLeftContainer.setLayout(new java.awt.BorderLayout());

        lblDistance.setText("");
        lblDistance.setMinimumSize(new java.awt.Dimension(50, 14));
        pnlLeftContainer.add(lblDistance, java.awt.BorderLayout.EAST);

        pnlInfoBar.add(pnlLeftContainer, java.awt.BorderLayout.WEST);

        pnlTitle.setBorder(javax.swing.BorderFactory.createEmptyBorder(7, 10, 1, 1));
        pnlTitle.setOpaque(false);
        pnlTitle.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        lblTitle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/openrule.title.png"))); // NOI18N
        pnlTitle.add(lblTitle);

        pnlInfoBar.add(pnlTitle, java.awt.BorderLayout.CENTER);

        pnlFormControls.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        pnlFormControls.setOpaque(false);
        pnlFormControls.setLayout(new javax.swing.BoxLayout(pnlFormControls, javax.swing.BoxLayout.LINE_AXIS));

        pnlButtons.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 1, 1, 1));
        pnlButtons.setOpaque(false);
        pnlButtons.setLayout(new javax.swing.BoxLayout(pnlButtons, javax.swing.BoxLayout.LINE_AXIS));
        pnlButtons.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                defaultCursor();
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                moveCursor();
            }
        });

        btnFlip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/swap.vert.png"))); // NOI18N
        btnFlip.setBorder(null);
        btnFlip.setMaximumSize(new java.awt.Dimension(16, 16));
        btnFlip.setMinimumSize(new java.awt.Dimension(16, 16));
        btnFlip.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/swap.vert.hover.png"))); // NOI18N
        btnFlip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flipRuler();
            }
        });

        btnFlip.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                defaultCursor();
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                moveCursor();
            }
        });
        pnlButtons.add(btnFlip);

        pnlPadding.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 2, 1, 2));
        pnlPadding.setOpaque(false);
        pnlPadding.setLayout(new javax.swing.BoxLayout(pnlPadding, javax.swing.BoxLayout.LINE_AXIS));

        btnMin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/minimize.png"))); // NOI18N
        btnMin.setBorder(null);
        btnMin.setMaximumSize(new java.awt.Dimension(16, 16));
        btnMin.setMinimumSize(new java.awt.Dimension(16, 16));
        btnMin.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/minimize.hover.png"))); // NOI18N
        btnMin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minimizeRuler();
            }
        });

        btnMin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                defaultCursor();
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                moveCursor();
            }
        });
        pnlPadding.add(btnMin);

        pnlButtons.add(pnlPadding);

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/close.png"))); // NOI18N
        btnClose.setBorder(null);
        btnClose.setBorderPainted(false);
        btnClose.setContentAreaFilled(false);
        btnClose.setMaximumSize(new java.awt.Dimension(16, 16));
        btnClose.setMinimumSize(new java.awt.Dimension(16, 16));
        btnClose.setPreferredSize(new java.awt.Dimension(16, 16));
        btnClose.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/close.hover.png"))); // NOI18N
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeRuler();
            }
        });

        btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                defaultCursor();
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                moveCursor();
            }
        });
        pnlButtons.add(btnClose);

        pnlFormControls.add(pnlButtons);

        pnlResize.setOpaque(false);
        pnlResize.setPreferredSize(new java.awt.Dimension(12, 12));
        pnlResize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                pnlResizeMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                pnlResizeMouseReleased(evt);
            }
        });
        pnlResize.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                pnlResizeMouseDragged(evt);
            }
        });
        pnlResize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                resizeWidthCursor();
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                defaultCursor();
            }
        });
        pnlResize.setLayout(null);

        lblHandle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/leadiv/openrule/gfx/resize.png"))); // NOI18N
        pnlResize.add(lblHandle);
        lblHandle.setBounds(0, 0, 12, 12);

        pnlFormControls.add(pnlResize);

        pnlInfoBar.add(pnlFormControls, java.awt.BorderLayout.EAST);

        pnlRulerContainer.add(pnlInfoBar);

        pnlTickBar.setOpaque(false);
        pnlTickBar.setPreferredSize(new java.awt.Dimension(360, 40));
        pnlTickBar.setLayout(new javax.swing.BoxLayout(pnlTickBar, javax.swing.BoxLayout.LINE_AXIS));

        tickbar.setOpaque(false);
        pnlTickBar.add(tickbar);

        pnlRulerContainer.add(pnlTickBar);

        getContentPane().add(pnlRulerContainer);

        //tickLeaderBar1.setPos(10);
        tickLeaderBar1.setOpaque(false);
        tickLeaderBar1.setLayout(new java.awt.BorderLayout());
        getContentPane().add(tickLeaderBar1);

        mbHotKeys.setPreferredSize(new java.awt.Dimension(56, 0));

        mnuHotKeys.setText("File");

        mtmHKFlip.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, 0));
        mtmHKFlip.setText("Item");
        mnuHotKeys.add(mtmHKFlip);
        mtmHKFlip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flipRuler();
            }
        });

        mtmHKSnap.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, 0));
        mtmHKSnap.setText("Item");
        mnuHotKeys.add(mtmHKSnap);
        mtmHKSnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                snap();
            }
        });

        mtmHKPreferences.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, 0));
        mtmHKPreferences.setText("Item");
        mnuHotKeys.add(mtmHKPreferences);
        mtmHKPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prefsRuler();
            }
        });

        mtmHKAbout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, 0));
        mtmHKAbout.setText("Item");
        mnuHotKeys.add(mtmHKAbout);
        mtmHKAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                about();
            }
        });

        mtmHKHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        mtmHKHelp.setText("Item");
        mnuHotKeys.add(mtmHKHelp);
        mtmHKHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gotohelp();
            }
        });

        mtmHKMinimize.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, 0));
        mtmHKMinimize.setText("Item");
        mnuHotKeys.add(mtmHKMinimize);
        mtmHKMinimize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minimizeRuler();
            }
        });

        mtmHKQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, 0));
        mtmHKQuit.setText("Item");
        mnuHotKeys.add(mtmHKQuit);
        mtmHKQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeRuler();
            }
        });

        mbHotKeys.add(mnuHotKeys);

        setJMenuBar(mbHotKeys);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void setUnitProfile(UnitProfile p) {
        this.tickbar.setLabels(p.getLabels());
        this.tickbar.setPercision(p.getPrecision());
        this.tickbar.setPolicy(p.getTickPolicy());

        this.resolution = p.getResolution();
        this.precision = p.getPrecision();
        this.unitname = "(" + p.getName() + ")";

        this.tickbar.validate();
        this.tickbar.repaint();
    }

    public Color getRulerColor()
    {
        return this.pnlRulerContainer.getBackground();
    }
    
    public void setRulerColor(Color c)
    {
        this.pnlRulerContainer.setBackground(c);
    }
    
private void pnlResizeMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlResizeMouseDragged
    if(blnFollowMouse)
    {
        JComponent src = (JComponent)evt.getSource();
        Point ptMouseDragLoc = src.getLocationOnScreen();
        ptMouseDragLoc.translate(evt.getX(), evt.getY());
        Point ptFormLoc = this.getLocationOnScreen();
        int newWidth = ptMouseDragLoc.x - ptFormLoc.x;
        
        Dimension dimRulerSize = this.getSize();
        
        dimRulerSize.width = newWidth;
        this.setSize(dimRulerSize);
    }
}//GEN-LAST:event_pnlResizeMouseDragged

private void pnlResizeMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlResizeMousePressed
    this.blnFollowMouse = true;
}//GEN-LAST:event_pnlResizeMousePressed

private void pnlResizeMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlResizeMouseReleased
    this.blnFollowMouse = false;
}//GEN-LAST:event_pnlResizeMouseReleased

private void pnlRulerContainerMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlRulerContainerMouseDragged
    if(blnFollowMouse)
    {
        JComponent src = (JComponent)evt.getSource();
        Point ptCurrentCursorPos = src.getLocationOnScreen();
        ptCurrentCursorPos.translate(evt.getX(), evt.getY());
        Point ptRulerPos = this.getLocationOnScreen();
        
        ptRulerPos.translate(ptCurrentCursorPos.x - ptLastCursorPos.x, ptCurrentCursorPos.y - ptLastCursorPos.y);
        this.setLocation(ptRulerPos);
        ptLastCursorPos = (Point) ptCurrentCursorPos.clone();
    }
}//GEN-LAST:event_pnlRulerContainerMouseDragged

private void pnlRulerContainerMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlRulerContainerMouseMoved
    int pos = evt.getX();

    String labelFrmt = "%." + this.precision + "f " + this.unitname;
    this.lblDistance.setText(String.format(labelFrmt, pos / this.resolution));
    this.tickLeaderBar1.setPos(pos);
}//GEN-LAST:event_pnlRulerContainerMouseMoved

private void pnlRulerContainerMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlRulerContainerMousePressed
    JComponent src = (JComponent)evt.getSource();
    ptLastCursorPos = src.getLocationOnScreen();
    ptLastCursorPos.translate(evt.getX(), evt.getY());
    this.blnFollowMouse = true;
}//GEN-LAST:event_pnlRulerContainerMousePressed

private void pnlRulerContainerMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlRulerContainerMouseReleased
    this.blnFollowMouse = false;
}//GEN-LAST:event_pnlRulerContainerMouseReleased

private void moveRuler(String direction, HashMap extras) {
    fireRulerEvent(new com.leadiv.openrule.event.RulerEvent(com.leadiv.openrule.event.RulerListener.NUDGE, this, direction, extras));
}

private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
    this.requestFocusInWindow();
}//GEN-LAST:event_formWindowActivated

private void formWindowLostFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowLostFocus
    if(this.isTransparable && this.transparencyProfile.equals("focus")) {
        AWTUtilitiesWrapper.setWindowOpacity(this, this.transparency);
    }
}//GEN-LAST:event_formWindowLostFocus

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    if(this.isTransparable && this.transparencyProfile.equals("focus")) {
        AWTUtilitiesWrapper.setWindowOpacity(this, 1);
    }
}//GEN-LAST:event_formWindowGainedFocus

private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
    HashMap<String, String> extras = new HashMap<String, String>();

    if(evt.isControlDown()) extras.put("skip", "10");

    if(evt.getKeyCode() == KeyEvent.VK_DOWN) {
        moveRuler("down", extras);
        return;
    }

    if(evt.getKeyCode() == KeyEvent.VK_UP) {
        moveRuler("up", extras);
        return;
    }

    if(evt.getKeyCode() == KeyEvent.VK_LEFT) {
        moveRuler("left", extras);
        return;
    }

    if(evt.getKeyCode() == KeyEvent.VK_RIGHT) {
        moveRuler("right", extras);
        return;
    }
}//GEN-LAST:event_formKeyPressed

public Dimension getRulerSize() {
    Dimension overall = this.getSize();
    Dimension leader = this.tickLeaderBar1.getSize();

    return new Dimension(overall.width, overall.height - leader.height);
}

public String getTransparencyProfile() {
    return transparencyProfile;
}

public void setTransparencyProfile(String transparencyProfile) {
    this.transparencyProfile = transparencyProfile;

    java.util.prefs.Preferences p = Preferences.userPrefs();
    this.transparency = p.getFloat("transparency", Preferences.DEFAULT_TRANSPARENCY);

    if(this.isTransparable) {
        if(this.transparencyProfile.equals("never")) {
            AWTUtilitiesWrapper.setWindowOpacity(this, 1);

        } else if(this.transparencyProfile.equals("focus")) {
            AWTUtilitiesWrapper.setWindowOpacity(this, this.transparency);
            if(this.isFocused()) {
                AWTUtilitiesWrapper.setWindowOpacity(this, 1);
            }

        } else if(this.transparencyProfile.equals("always")) {
            AWTUtilitiesWrapper.setWindowOpacity(this, this.transparency);
        }
    }
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnFlip;
    private javax.swing.JButton btnMin;
    private javax.swing.JLabel lblDistance;
    private javax.swing.JLabel lblHandle;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JMenuBar mbHotKeys;
    private javax.swing.JMenu mnuHotKeys;
    private javax.swing.JMenuItem mtmAbout;
    private javax.swing.JMenuItem mtmFlip;
    private javax.swing.JMenuItem mtmHKAbout;
    private javax.swing.JMenuItem mtmHKFlip;
    private javax.swing.JMenuItem mtmHKHelp;
    private javax.swing.JMenuItem mtmHKMinimize;
    private javax.swing.JMenuItem mtmHKPreferences;
    private javax.swing.JMenuItem mtmHKQuit;
    private javax.swing.JMenuItem mtmHKSnap;
    private javax.swing.JMenuItem mtmHelp;
    private javax.swing.JMenuItem mtmMinimize;
    private javax.swing.JMenuItem mtmPreferences;
    private javax.swing.JMenuItem mtmQuit;
    private javax.swing.JSeparator mtmSeparator;
    private javax.swing.JSeparator mtmSeparator2;
    private javax.swing.JMenuItem mtmSnap;
    private javax.swing.JPanel pnlButtons;
    private javax.swing.JPanel pnlFormControls;
    private javax.swing.JPanel pnlInfoBar;
    private javax.swing.JPanel pnlLeftContainer;
    private javax.swing.JPanel pnlPadding;
    private javax.swing.JPanel pnlResize;
    private javax.swing.JPanel pnlRulerContainer;
    private javax.swing.JPanel pnlTickBar;
    private javax.swing.JPanel pnlTitle;
    private javax.swing.JPopupMenu popContextMenu;
    private com.leadiv.openrule.TickLeaderBar tickLeaderBar1;
    private com.leadiv.openrule.TickBar tickbar;
    // End of variables declaration//GEN-END:variables
    private Point ptLastCursorPos;
    private boolean blnFollowMouse = true;
    private String transparencyProfile = "never";
    private Float transparency = 1f;
    private boolean isTransparable;
    private Float resolution = 1f;
    private int precision = 0;
    private String unitname = "(Pixel)";
}
